<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			//.和-没有解决
			//var reg=/^\w+@\w+(\.\w+)+$/;
			//var reg=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
			  var reg  =  /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

			var str=window.prompt("input a email:");
			alert(reg.test(str));
		</script>
	</head>
	<body>
		<form action="3.html">
			<input type="email" id="em" name="em" onblur="chekE(this)" required/>
			<input type="submit"/>
		</form>
		<script>
			function chekE(e){
				//var e=document.getElementById("em");
				if(e.validity.valueMissing){
					e.setCustomValidity("邮件很重要，必须填写");
					return false;
				}else if(e.validity.typeMismatch){
					e.setCustomValidity("邮件的格式用xxx@xx.yy的格式");
					return false;
				}
				return true;
			}
			
		</script>
	</body>
</html>
